package net.wsfcp.android.http.mvp.presenter;

import net.wsfcp.android.base.BasePresenter;
import net.wsfcp.android.bean.resultbean.AddressBean;
import net.wsfcp.android.http.mvp.IModel;
import net.wsfcp.android.http.mvp.contract.AddressContract;
import net.wsfcp.android.http.mvp.model.AddressModel;
import net.wsfcp.android.ui.view.my.fragment.AddressFragment;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by Shaoboyang on 2018/12/14.
 */
//修改地址
public class EditAddressPresenter extends BasePresenter<AddressFragment> implements
        AddressContract.EditAddressPresenter {


    @Override
    public void getAddressList() {
        ((AddressModel) getiModelMap().get("list")).getAddressList(new AddressModel
                .GetAddressListInfoHint() {
            @Override
            public void getAddressListSuccessInfo(ArrayList<AddressBean> bean) {
                getIView().getAddressListSuccess(bean);
            }

            @Override
            public void getAddressListFailInfo(String str) {
                getIView().getAddressListFail(str);
            }


        });
    }

    @Override
    public void setDefaultAddress(String id) {
        ((AddressModel) getiModelMap().get("default")).setDefaultAddress(id, new AddressModel
                .SetDefaultAddressInfoHint() {
            @Override
            public void setDefaultAddressSuccessInfo() {
                getIView().setDefaultAddressSuccess();
            }

            @Override
            public void setDefaultAddressFailInfo(String str) {
                getIView().setDefaultAddressFail(str);
            }


        });
    }

    @Override
    public void deleteAddress(String id) {
        ((AddressModel) getiModelMap().get("delete")).deleteAddress(id, new AddressModel
                .DeleteAddressInfoHint() {
            @Override
            public void deleteAddressSuccessInfo() {
                getIView().deleteAddressSuccess();
            }

            @Override
            public void deleteAddressFailInfo(String str) {
                getIView().deleteAddressFail(str);
            }


        });

    }

    @Override
    public HashMap<String, IModel> getiModelMap() {
        return loadModelMap(new AddressModel());
    }

    @Override
    public HashMap<String, IModel> loadModelMap(IModel... models) {
        HashMap<String, IModel> map = new HashMap<>();
        map.put("list", models[0]);
        map.put("default", models[0]);
        map.put("delete", models[0]);
        return map;
    }


}
